/*
 * Publisher.java
 * Copyright (C) Jul 4, 2012 Bora SAYINER
 *
 * This file is part of Design Patterns.
 *
 * Design Patterns is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * Design Patterns is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Design Patterns. If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package net.samples.observer;

import java.util.ArrayList;

/**
 * 
 * @author Bora SAYINER
 * @since Jul 4, 2012
 * @version 1.0.0
 */
public class NuclearReactor implements IObservable {

	private final ArrayList<IObserver> observers = new ArrayList<>();

	private int temp;

	@Override
	public void addObserver(IObserver observer) {
		this.observers.add(observer);
	}

	@Override
	public void removeObserver(IObserver observer) {
		int index = observers.indexOf(observer);
		if (index >= 0) {
			observers.remove(index);
		}
	}

	@Override
	public void notifyObservers() {
		for (IObserver observer : observers) {
			observer.update(temp);
		}
	}

	public void incrementTemp() {
		temp++;
		if (temp > 100) {
			notifyObservers();
		}
	}

	public void decrementTemp() {
		temp--;
	}

}
